home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / magplip / source / magplip.h < prev    next >
C/C++ Source or Header  |  1995-08-20  |  10KB  |  279 lines

  1. #ifndef __MAGPLIP_H
  2. #define __MAGPLIP_H
  3. /*
  4. ** $VER: magplip.h 1.7 (13 Aug 1995)
  5. **
  6. ** magplip.device - Parallel Line Internet Protocol
  7. **
  8. ** Original code written by Oliver Wagner and Michael Balzer.
  9. **
  10. ** This version has been completely reworked by Marius Gröger,
  11. ** introducing slight protocol changes. The new source is
  12. ** a lot better organized and maintainable.
  13. **
  14. ** Additional changes and code cleanup by Jan Kratochvil and Martin Mares.
  15. ** The new source is significantly faster and yet better maintainable.
  16. **
  17. ** (C) Copyright 1993-1994 Oliver Wagner & Michael Balzer
  18. ** (C) Copyright 1995 Marius Gröger
  19. ** (C) Copyright 1995 Jan Kratochvil & Martin Mares
  20. **     All Rights Reserved
  21. **
  22. ** $HISTORY:
  23. **
  24. ** 13 Aug 1995 : 001.007 :  code cleanup
  25. ** 29 Jul 1995 : 001.006 :  support for arbitration delay
  26. ** 24 Jul 1995 : 001.005 :  only one delay value in config
  27. **                          some volatile elements in GD
  28. ** 25 Apr 1995 : 001.004 :  #define's FAR
  29. ** 06 Mar 1995 : 001.003 :  added collision delays
  30. ** 04 Mar 1995 : 001.002 :  packet-type now ULONG
  31. ** 18 Feb 1995 : 001.001 :  some SAS/C wrappers, better data base handling
  32. ** 12 Feb 1995 : 001.000 :  reworked original
  33. */
  34.  
  35.    /* system header files */
  36. #ifndef DEVICES_SANA2_H
  37. #include <devices/sana2.h>
  38. #endif
  39. #ifndef EXEC_SEMAPHORES_H
  40. #include <exec/semaphores.h>
  41. #endif
  42. #ifndef EXEC_LISTS_H
  43. #include <exec/lists.h>
  44. #endif
  45. #ifndef EXEC_INTERRUPTS_H
  46. #include <exec/interrupts.h>
  47. #endif
  48. #ifndef EXEC_LIBRARIES_H
  49. #include <exec/libraries.h>
  50. #endif
  51. #ifndef DOS_DOS_H
  52. #include <dos/dos.h>
  53. #endif
  54.  
  55.  
  56. /****************************************************************************/
  57.  
  58.  
  59. #ifdef __SASC
  60. #  define ASM     __asm
  61. #  define REG(x)  register __ ## x
  62. #  define INLINE  __inline
  63. #  define REGARGS __regargs
  64. #  define SAVEDS  __saveds
  65. #  define FAR     __far
  66. #else
  67. #  error Please define ASM and REG for your compiler
  68. #endif
  69.  
  70.  
  71. /****************************************************************************/
  72.  
  73.  
  74.    /* memory economy is *everything* :-) */
  75. #define SERVERTASKNAME           pb->pb_DevNode.lib_Node.ln_Name
  76.  
  77.       /* default values */
  78. #define PLIP_DEFMTU              1024
  79. #define PLIP_DEFBPS              100000
  80. #define PLIP_DEFRETRIES          63
  81. #define PLIP_DEFTIMEOUT          300000
  82. #define PLIP_DEFDELAY            150000
  83. #define PLIP_DELAYDIFF           50000
  84. #define PLIP_DEFARBITRATIONDELAY 500
  85.  
  86.       /* maximum values */
  87. #define PLIP_MAXMTU              8192
  88. #define PLIP_MAXRETRIES          127   /* this is really the maximum, don't */
  89.                                                       /* try higher values! */
  90.  
  91.  
  92. /****************************************************************************/
  93.  
  94.  
  95. #define PKTFRAMESIZE_1           4        /* the sync-field and packet-size */
  96. #define PKTFRAMESIZE_2           6                   /* crc and packet type */
  97.  
  98. struct PLIPFrame {
  99.    USHORT   pf_Sync;
  100.    SHORT    pf_Size;
  101.    USHORT   pf_CRC;
  102.    ULONG    pf_Type;
  103.    UBYTE    pf_Data[PLIP_MAXMTU];
  104. };
  105.  
  106.  
  107. #define SYNCBYTE_HEAD   0x42
  108. #define SYNCBYTE_CRC    0x01
  109. #define SYNCBYTE_NOCRC  0x02
  110. #define SYNCWORD_CRC    ((SYNCBYTE_HEAD << 8) | SYNCBYTE_CRC)
  111. #define SYNCWORD_NOCRC  ((SYNCBYTE_HEAD << 8) | SYNCBYTE_NOCRC)
  112.  
  113.  
  114. /****************************************************************************/
  115.  
  116.  
  117. struct TrackRec {
  118.    struct MinNode              tr_Link;
  119.    ULONG                       tr_PacketType;
  120.    struct Sana2PacketTypeStats tr_Sana2PacketTypeStats;
  121. };
  122.  
  123.  
  124. /****************************************************************************/
  125.  
  126.  
  127. typedef BOOL (* ASM BMFunc)(REG(a0) void *, REG(a1) void *, REG(d0) LONG);
  128.  
  129. struct BufferManagement
  130. {
  131.     struct MinNode   bm_Node;
  132.     BMFunc           bm_CopyFromBuffer;
  133.     BMFunc           bm_CopyToBuffer;
  134. };
  135.  
  136.  
  137. /****************************************************************************/
  138.  
  139.  
  140. struct PLIPBase {
  141.    struct Library              pb_DevNode;        /* basic device structure */
  142.    UWORD                       pb_pad1; /* make the following long alligned */
  143.    BPTR                        pb_SegList;               /* pointer to code */
  144.    struct Library          *   pb_MiscBase,          /* various libs & res. */
  145.                            *   pb_CIAABase,
  146.                            *   pb_UtilityBase,
  147.                            *   pb_TimerBase,
  148.                            *   pb_DOSBase,
  149.                            *   pb_SysBase;
  150.    struct Process          *   pb_Server;             /* main server proces */
  151.    struct Task             *   pb_Task;         /* used for server shutdown */
  152.    struct Interrupt            pb_Interrupt;          /* for AddICRVector() */
  153.    ULONG                       pb_IntSig;        /* sent from int to server */
  154.    ULONG                       pb_IntSigMask;                  /* for speed */
  155.    ULONG                       pb_ServerStoppedSigMask;     /* for shutdown */
  156.    struct MsgPort          *   pb_ServerPort;       /* for IOReq forwarding */
  157.    struct MsgPort          *   pb_TimerPort;      /* for collision handling */
  158.    struct timerequest          pb_TimeReq;                          /* dito */
  159.    struct Sana2DeviceStats     pb_DevStats;            /* SANA-2 wants this */
  160.    volatile struct List        pb_ReadList,                  /* the readers */
  161.                                pb_WriteList,                 /* the writers */
  162.                                pb_EventList,              /* event tracking */
  163.                                pb_ReadOrphanList,   /* for spurious packets */
  164.                                pb_TrackList,                  /* track type */
  165.                                pb_BufferManagement;          /* Copy-In/Out */
  166.    struct SignalSemaphore      pb_EventListSem,     /* protection for lists */
  167.                                pb_ReadListSem,
  168.                                pb_WriteListSem,
  169.                                pb_TrackListSem,
  170.                                pb_ReadOrphanListSem,
  171.                                pb_Lock;
  172.    ULONG                       pb_Retries;                 /* config values */
  173.    ULONG                       pb_ReportBPS;
  174.    ULONG                       pb_MTU;
  175.    ULONG                       pb_AllocFlags;
  176.    ULONG                       pb_Timeout;
  177.    LONG                        pb_CollisionDelay;
  178.    LONG                        pb_ArbitrationDelay;
  179.    UBYTE                       pb_pad2;
  180.    volatile UBYTE              pb_Flags;                       /* see below */
  181.    UBYTE                       pb_HandshakeMask[2],   /* crossed for side-a */
  182.                                pb_HandshakeBit[2];            /* and side-b */
  183.    volatile struct PLIPFrame   pb_SendFrame,
  184.                                pb_ReceiveFrame;
  185. };
  186.  
  187.    /*
  188.    ** used as index for PLIPBase->pb_HandshakeMask[]/pb_HandshakeBit[]
  189.    */
  190. #define HS_LINE        0   /* as we use compatible plip wireing, our magic */
  191. #define HS_REQUEST     1   /* is to cross the lines transparently by software */
  192.  
  193. #ifdef __SASC
  194.      /*
  195.      ** redirect all shared library bases to our device base.
  196.      */
  197. #  define SysBase      pb->pb_SysBase
  198. #  define DOSBase      pb->pb_DOSBase
  199. #  define TimeBase     pb->pb_TimeBase
  200. #  define UtilityBase  pb->pb_UtilityBase
  201. #  define MiscBase     pb->pb_MiscBase
  202. #  define CIAABase     pb->pb_CIAABase
  203. #  define CiaBase      pb->pb_CIAABase
  204. #  define TimerBase    pb->pb_TimerBase
  205.      /*
  206.      ** This macro declares a local variable which temporary gets
  207.      ** SysBase directly from AbsExecBase.
  208.      */
  209. #  define LOCALSYSBASE struct { void *pb_SysBase; } *pb = (void*)0x4
  210.      /*
  211.      ** Use this macro as argument for all functions which need to
  212.      ** have access to your data base.
  213.      */
  214. #  define BASEPTR      struct PLIPBase *pb
  215. #else
  216. #  error Please define library bases for your compiler
  217. #endif
  218.  
  219.    /*
  220.    ** Values for PLIPBase->pb_Flags
  221.    ** Note that the Flags field is intentionally only 8 bits wide so that
  222.    ** the ASM parts my use the bit functions.
  223.    */
  224. #define PLIPB_SIDEA           0   /* we are side A (not B :-) */
  225. #define PLIPB_EXCLUSIVE       1   /* current opener is exclusive */
  226. #define PLIPB_NOTCONFIGURED   2   /* not configured */
  227. #define PLIPB_OFFLINE         3   /* currently not online (sic!) */
  228. #define PLIPB_SENDCRC         4   /* send with CRC sum */
  229. #define PLIPB_RECEIVING       5   /* set by interrupt */
  230. #define PLIPB_COLLISION       6   /* arbitration detected a collision */
  231. #define PLIPB_SERVERSTOPPED   7   /* set by server while passing away */
  232.  
  233. #define PLIPF_SIDEA           (1<<PLIPB_SIDEA)
  234. #define PLIPF_EXCLUSIVE       (1<<PLIPB_EXCLUSIVE)
  235. #define PLIPF_NOTCONFIGURED   (1<<PLIPB_NOTCONFIGURED)
  236. #define PLIPF_OFFLINE         (1<<PLIPB_OFFLINE)
  237. #define PLIPF_SENDCRC         (1<<PLIPB_SENDCRC)
  238. #define PLIPF_RECEIVING       (1<<PLIPB_RECEIVING)
  239. #define PLIPF_COLLISION       (1<<PLIPB_COLLISION)
  240. #define PLIPF_SERVERSTOPPED   (1<<PLIPB_SERVERSTOPPED)
  241.  
  242.  
  243. /****************************************************************************/
  244.  
  245.  
  246.    /*
  247.    ** sent to the server task after being CreateNewProc()ed
  248.    */
  249. struct ServerStartup
  250. {
  251.    struct Message    ss_Msg;
  252.    struct PLIPBase  *ss_PLIPBase;
  253. };
  254.  
  255.  
  256. /****************************************************************************/
  257.  
  258.  
  259.    /*
  260.    ** configuration stuff
  261.    */
  262. #define CONFIGFILE "ENV:SANA2/magPLIP.config"
  263.  
  264. #define TEMPLATE "TIMEOUT/K/N,PRIORITY=PRI/K/N,MTU/K/N,BPS/K/N,RETRIES/K/N,SENDCRC/S,CD=COLLISIONDELAY/K/N,AD=ARBITRATIONDELAY/K/N"
  265.  
  266. struct PLIPConfig
  267. {
  268.       ULONG *timeout;
  269.       LONG  *priority;
  270.       LONG  *mtu;
  271.       LONG  *bps;
  272.       LONG  *retries;
  273.       ULONG  sendcrc;
  274.       LONG  *collisiondelay;
  275.       LONG  *arbitrationdelay;
  276. };
  277.  
  278. #endif
  279.